﻿using Newtonsoft.Json;
using System.Collections;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace PesticideManage.API.Services.Files.Models;
public sealed class Classification
{
    [Key]
    [StringLength(255)]
    public string Name { get; set; } = string.Empty;
}
public class ShangFile
{
    private string _name = string.Empty;
    [StringLength(255)]
    public string Name
    {
        get
        {
            if (string.IsNullOrEmpty(_name))
            {
                _name = FileName;
            }
            return _name;
        }
        set => _name = value;
    }
    [StringLength(255)]
    public string FileName { get; set; } = string.Empty;
    public ShangFile()
    {

    }
    public ShangFile(string fileName)
    {
        FileName = fileName;
        ClassificationName ??= GetFileType(fileName);
    }
    private static string GetFileType(string fileName)
    {
        string fileExtension = Path.GetExtension(fileName);
        return fileExtension switch
        {
            ".jpg" or ".png" => "image",
            ".txt" => "text",
            ".mp4" => "video",
            _ => "application",
        };
    }
    [StringLength(255)]
    public string? Url { get; set; }
    [ForeignKey(nameof(ClassificationName))]
    public Classification? Classification { get; set; }
    public string? ClassificationName { get; set; }

}
